home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form Form1
- Caption = "Device name and port"
- ClientHeight = 975
- ClientLeft = 1080
- ClientTop = 1650
- ClientWidth = 7485
- Height = 1380
- Left = 1020
- LinkTopic = "Form1"
- ScaleHeight = 975
- ScaleWidth = 7485
- Top = 1305
- Width = 7605
- Begin Label Label1
- AutoSize = -1 'True
- Caption = "Label1"
- Height = 195
- Left = 360
- TabIndex = 0
- Top = 300
- Width = 585
- End
- '... This function converts a windows API LPstring to a VB string.
- Function FixAPIString$ (ByVal test$)
- FixAPIString$ = Trim(Left$(test$, InStr(test$, Chr$(0)) - 1))
- End Function
- Sub Form_Load ()
- Dim dev$, devname$, devoutput$
- dev$ = GetDefPrinter$() ' Get default printer info
- If dev$ = "" Then GoTo jump1
- devname$ = GetDeviceName$(dev$)' Strip the device name from dev$
- devoutput$ = GetDeviceOutput$(dev$)' Strip the device port from dev$
- label1.Caption = devname$ + " on " + devoutput$
- GoTo jump2
- jump1:
- label1.Caption = "No device found"
- jump2:
- End Sub
- ' This function retrieves the definition of the default
- ' printer on this system contained in the win.ini file.
- Function GetDefPrinter$ ()
- Dim def$
- def$ = String$(128, 0)
- di% = GetProfileString%("windows", "device", "", def$, Len(def$))
- def$ = FixAPIString$(def$)
- GetDefPrinter$ = def$
- End Function
- ' Retrieves the name portion of a device string.
- Function GetDeviceName$ (dev$)
- Dim npos%
- npos% = InStr(dev$, ",")
- GetDeviceName$ = Left$(dev$, npos% - 1)
- End Function
- ' Returns the output destination for the specified
- ' device.
- Function GetDeviceOutput$ (dev$)
- Dim firstpos%, nextpos%
- firstpos% = InStr(dev$, ",")
- nextpos% = InStr(firstpos% + 1, dev$, ",")
- GetDeviceOutput$ = Mid$(dev$, nextpos% + 1)
- End Function
-